import router from './router/index'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import {
  getToken
} from './utils/auth.js'

NProgress.configure({
  showSpinner: false
})

const whiteList = ['/LoginMove', '/Login']

router.beforeEach((to, from, next) => {
  let width = window?.innerWidth;
  // to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
  NProgress.start()
  if (getToken()) {
    // 当有token时候正常跳转
    if (whiteList.indexOf(to.path) !== -1) {
      next('/')
    } else {
      // console.log(to, from, next, '5555555555555555555');
      // if (!localStorage.getItem('status')) {
      //   return
      // }
      next()
    }
  } else {
    // 当没有token是跳转到login页面
    if (width < 400) {
      // 跳转到移动端登陆页面
      console.log(whiteList.indexOf(to.path));
      if (whiteList.indexOf(to.path) !== -1) {
        next()
      } else {
        next('/LoginMove')
      }
    } else {
      // 跳转到Pc端登陆页面
      // next('/LoginMove')
      if (whiteList.indexOf(to.path) !== -1) {
        next()
      } else {
        // console.log('11111111111111111111111111111111111111111111111111');
        next('/Login')
      }
    }

  }
})
router.afterEach(() => {
  NProgress.done()
})